<?php

namespace app\common\validate;

use think\Validate;
use app\lib\exception\BaseException;

class BaseValidate extends Validate
{
    public function goCheck($scene='') {
        //获取请求传递过来的参数
        $params = request()->param();
        $check = empty($scene)?$this->check($params):$this->scene($scene)->check($params);
        //实例化验证器
        if (!$check) {
            throw new BaseException(['msg' => $this->getError(), 'errCode' => 10000,'code'=>400]);
        }
        return true;
    }

    protected function isPefectCode($value, $rule='', $data='', $field=''){
        //验证码不存在
        $beforeCode = cache($data['phone']);
        if (!$beforeCode) return "请重新获取验证码";

        //检查验证码
        if ($value != $beforeCode) return '验证码错误';

        return true;
    }
}
